package com.shujia.core

import org.apache.spark.{SparkConf, SparkContext}

object Demo1Map {
  def main(args: Array[String]): Unit = {

    /**
      * map算子
      * 传入一行返回一行
      * 传入一对象返回一对象
      */


    val conf = new SparkConf()
      .setMaster("local") //本地运行
      .setAppName("map")

    val sc = new SparkContext(conf)

    //读取文件创建rdd
    val studentRDD = sc.textFile("data/student.txt")

    val kvRDD = studentRDD.map(line => {
      val split = line.split(",")

      val age = split(2).toInt
      val name = split(1)

      (name, age)
    })

    kvRDD.foreach(println)


  }

}
